﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using StyleMVVM.DependencyInjection;

#if DOT_NET
using Microsoft.VisualStudio.TestTools.UnitTesting;
using StyleMVVM.DotNet.Aspects.Impl;

#else
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
#endif

namespace StyleMVVM.DotNet.Aspects.UnitTests
{

	public class BaseTestClass
	{
		protected bool registerMainApp = true;
		protected Bootstrapper bootstrapper;
		protected ExportEnvironment exportEnvironment = ExportEnvironment.RunTime;

		protected IDependencyInjectionContainer Container
		{
			get { return bootstrapper.Container; }
		}

		[TestInitialize]
		public void Setup()
		{
			bootstrapper = new Bootstrapper();

			bootstrapper.Container.Environment = exportEnvironment;

			bootstrapper.Container.RegisterAssembly(typeof(IAspect).Assembly);

			bootstrapper.Container.RegisterAssembly(
				GetType().GetTypeInfo().Assembly);

			bootstrapper.Start();
		}

		[TestCleanup]
		public void Teardown()
		{
			AspectClassManager.Instance = null;
			bootstrapper.Shutdown();

			if (Bootstrapper.HasInstance)
			{
				throw new Exception("bootstrapper did not cleanup");
			}

			GC.Collect();
		}
	}
}
